﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KeywordAuction
{

    public class AdvertiserBidding
    {
        public double ExpectedRevenue { get; set; }
        public double Bid { get; set; }
        public Advertiser Advertiser { get; set; }

        private AdvertiserBidding()
        {
            Bid = 0;
            ExpectedRevenue = 0;
        }

        public double GetValue()
        {
            int index = AttendingAdspot.GetIndexAdvertiser(this);
            if(index != -1)
            {
      
                double revenue = (AttendingAdspot.ClickThroughtRates[index] * ExpectedRevenue);
                double payment = AttendingAdspot.GetPaymentValue(index);
                return (revenue - payment) * AttendingAdspot.Traffic;
            }
            return 0; 
        
        }

        public Adspot AttendingAdspot { get; set; }

        public static AdvertiserBidding CreateAdvertiserBidding(Advertiser advertiser, Adspot adspot)
        {
            var bid = new AdvertiserBidding();
            bid.Advertiser = advertiser;
            bid.AttendingAdspot = adspot;
            return bid;
        }
    }
}
